package com.example.hotelmanagement.util;

public class ResponseResult<T> {
    private int code; // 状态码
    private String message; // 消息
    private T data; // 数据

    // 构造函数
    public ResponseResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public ResponseResult() {}

    // Getter 和 Setter
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    // 静态方法 - 成功响应
    public static <T> ResponseResult<T> success(T data) {
        return new ResponseResult<>(200, "Success", data);
    }

    public static <T> ResponseResult<T> success(String message, T data) {
        return new ResponseResult<>(200, message, data);
    }

    // 静态方法 - 失败响应
    public static <T> ResponseResult<T> failure(String message) {
        return new ResponseResult<>(500, message, null);
    }

    public static <T> ResponseResult<T> failure(int code, String message) {
        return new ResponseResult<>(code, message, null);
    }

    // 静态方法 - 空响应
    public static <T> ResponseResult<T> success() {
        return new ResponseResult<>(200, "Success", null);
    }

    public static <T> ResponseResult<T> failure() {
        return new ResponseResult<>(500, "Failure", null);
    }

    @Override
    public String toString() {
        return "ResponseResult{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
